package com.AnywheeBt.adapter;

import java.util.ArrayList;

import com.AnywheeBt.R;
import com.AnywheeBt.bean.BtContact;

import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class ContactAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private ArrayList<com.AnywheeBt.bean.BtContact> contacts;
    private int mSelectPosition = -1;
	private int nlayoutID=0;
	private int  selectItem=-1;

    public ContactAdapter(Context context, ArrayList<BtContact> contacts,int resource) {
        this.mContext = context;
        this.contacts = contacts;
		nlayoutID = resource;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return contacts.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return contacts.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub


		ViewHolder holder=null;                
		if (convertView == null) {  
			holder = new ViewHolder();    
			convertView = mInflater.inflate(nlayoutID, null);	
			holder.tv_name = (TextView) convertView.findViewById(R.id.pb_name);	
			holder.tv_text = (TextView) convertView.findViewById(R.id.pb_text);	
			convertView.setTag(holder);             
		} else {    
			holder = (ViewHolder) convertView.getTag();  
		}   
		if (position == selectItem) {    
			convertView.setBackgroundResource(R.drawable.bt_num);
		}  else {    
			convertView.setBackgroundResource(R.drawable.bt_num_n);
		}
		//*if (mListData!=null&&mListData.size()>0)
			{			
			holder.tv_name.setText(contacts.get(position).getName());	
			holder.tv_text.setText(contacts.get(position).getNumber());		
		}				 
		return convertView;   
    }
    
    public void setSelected(int p){
    	mSelectPosition = p;
    }
	public  void setSelectItem(int selectItem) {     
		this.selectItem = selectItem;    
	} 

    public void setDataChange(ArrayList<BtContact> contacts) {
        this.contacts = contacts;
        this.notifyDataSetChanged();
    }

	public class ViewHolder {
		TextView 	tv_name; 
		TextView 	tv_text; 
	}  


}
